<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>多个v-model，仅限于vue3中使用</title>
  </head>
  <body>
    <div id="app">
      <my-form
        @submit="print"
        v-model:username="username"
        v-model:password="password"
      ></my-form>
      {{ username }} -- {{ password }}
    </div>
  </body>
  <template id="form">
    <form @submit.prevent="$emit('submit')">
      <input
        type="text"
        :value="username"
        @input="$emit('update:username', $event.target.value)"
      />
      <input
        type="password"
        :value="password"
        @input="$emit('update:password', $event.target.value)"
      />
      <input type="submit" value="登录" />
    </form>
  </template>
  <script src="../lib/vue.global.js"></script>
  <script>
    const Form = {
      template: "#form",
      props: ["username", "password"],
      emits: ["update:username", "update:password"],
    };
    Vue.createApp({
      data() {
        return {
          username: "",
          password: "",
        };
      },
      methods: {
        print() {
          console.log({
            username: this.username,
            password: this.password,
          });
        },
      },
      components: {
        MyForm: Form,
      },
    }).mount("#app");
  </script>
</html>
